home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC07Jiffy.Wind / Jiffy.asm2 < prev    next >
Encoding:
Text File  |  1990-05-25  |  28.6 KB  |  789 lines  |  [04] ASCII Text (0x0000)

  1. *******************************************************************************
  2. *
  3. * Jiffy Windows - Pixel Transfer Demonstration
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Keith Rollin
  11. *
  12. *******************************************************************************
  13.  
  14. *******************************************************************************
  15. *
  16. doClose             start
  17. *
  18. * Description:      Closes the top window by hiding it. If it closes the last
  19. *                   window on the screen, the Close menu item is disabled.
  20. *
  21. *
  22. * Inputs:           NONE
  23. *
  24. * Outputs:          NONE
  25. *
  26. * External Refs:    NONE
  27. *
  28. * Entry Points:     NONE
  29. *
  30. *******************************************************************************
  31.                     using Globals
  32.  
  33. ; While closing the window, we have to get a little tricky. If we are closing
  34. ; the Odyssey window, then we have to enable the "Read a Book" menu item. If
  35. ; we are closing any of the Test window, we have to enable the "Open Test
  36. ; Windows" menu item. We perform this check by getting the pointer to the top
  37. ; window, and comparing it to the stored pointer to the Odyssey window. If they
  38. ; match, then we know we are closing the Odyssey window. If not, then we assume
  39. ; that we are closing a Test window. We don't have to worry about NDA windows
  40. ; getting in the way as those are taken care of TaskMaster before we ever get
  41. ; here.
  42. ;
  43.  
  44.                     pha                 ; get the front window
  45.                     pha
  46.                     _FrontWindow
  47.  
  48.                     stz WindType        ; Assume we're closing a test window.
  49.  
  50.                     lda 1,s             ; Check to see if we are closing
  51.                     cmp OdyWindow       ; the Odyssey window
  52.                     bne HideIt
  53.                     lda 3,s
  54.                     cmp OdyWindow+2
  55.                     bne HideIt
  56.  
  57.                     inc WindType        ; set flag to say we closed Odyssey
  58. HideIt              ANOP
  59.                     _HideWindow         ; hide the top window
  60.  
  61.                     lda WindType        ; did we close a test window?
  62.                     bne EnableOdy       ; no, enable "Read a Book"
  63.  
  64.                     PushWord #258       ; yes, so re-enable that menu item
  65.                     _EnableMItem        ; to let us re-open it.
  66.                     bra CheckForMoreWindows
  67.  
  68. EnableOdy           ANOP
  69.                     PushWord #259       ; re-enable Read A Book menu item
  70.                     _EnableMItem        ; to let us re-open it.
  71.  
  72. CheckForMoreWindows ANOP
  73.                     pha                 ; any more front windows?
  74.                     pha
  75.                     _FrontWindow
  76.  
  77.                     plx
  78.                     pla
  79.                     bne done            ; yes, so leave
  80.                     txa
  81.                     bne done            ; yes, so leave
  82.  
  83.                     PushWord #255       ; no, so disable close item
  84.                     _DisableMItem
  85.  
  86. done                ANOP
  87.                     rts
  88. WindType            ds 2
  89.                     end
  90.  
  91. *******************************************************************************
  92. *
  93. CacheContent        start
  94. *
  95. * Description:      This routine draws the contents of the window. Since it
  96. *                   is called from TaskMaster, we need to set the Direct Page
  97. *                   and Data Bank registers. The we prepare to draw the window.
  98. *                   First we check to see if there is a handle in the window's
  99. *                   RefCon, and make sure that it is not purged. If it is
  100. *                   still valid, it is used to update the window. If not, then
  101. *                   the window is drawn by hand.
  102. *
  103. *
  104. * Inputs:           NONE
  105. *
  106. * Outputs:          NONE
  107. *
  108. * External Refs:
  109. *                   Import GetOffScreenBuffer
  110. *                   Import DrawByHand
  111. *
  112. * Entry Points:
  113. *                   Export oldPort      ; used by DrawByHand
  114. *
  115. *******************************************************************************
  116.                     using Globals
  117.  
  118. ;
  119. ; CacheContents is called from the Window Manager to update the contents
  120. ; of the window. Therefore, the Direct Page and Data Bank Register may
  121. ; not be set to what our application had them set to. Save the settings
  122. ; as the Window Manager had them, and then set them up the way we like
  123. ; them. That way we can use local (2-byte absolute) addressing, and can
  124. ; access our Direct Page variables.
  125.  
  126.                     phd                 ; Save caller's direct page
  127.                     phb                 ; Save caller's data bank register
  128.  
  129.                     phk                 ; switch data bank to Program Bank
  130.                     plb
  131.                     lda MyDP            ; switch Direct Page to application's
  132.                     tcd
  133.  
  134. SetUp               ANOP
  135.  
  136. ; Get the port of the window that we have to update
  137.  
  138.                     pha                 ; space for result of GetWRefCon
  139.                     pha
  140.                     pha                 ; space for result of GetPort
  141.                     pha
  142.                     _GetPort
  143.  
  144.                     lda 1,s             ; save the current port for later
  145.                     sta oldPort         ; when we leave this routine. the port
  146.                     lda 3,s             ; gets changed if we have to draw into
  147.                     sta oldPort+2       ; the offscreen buffer.
  148.  
  149.                     _GetWRefCon         ; Get refcon, which holds a handle to
  150.                     PullLong Deref      ;   the cache record.
  151.  
  152.                     ldy #4              ; Lock the handle to the cache record.
  153.                     lda [Deref],y       ; We do this using the method documented
  154.                     ora #attrLocked     ; in the description of HLock in the
  155.                     sta [Deref],y       ; memory manager chapter.
  156.                     dey
  157.                     dey
  158.                     lda [Deref],y       ; Dereference it. Get a pointer to the
  159.                     sta CPPtr+2         ; cache record.
  160.                     lda [Deref]
  161.                     sta CPPtr
  162.  
  163.                     ldy #4              ; See if we have cached the contents.
  164.                     lda [CPPtr],y       ; We determine this by seeing if the
  165.                     iny                 ; pointer is a NULL pointer.
  166.                     iny
  167.                     ora [CPPtr],y       ; see if the pointer is $0000 0000
  168.                     bne haveBuffer      ; no it's not, so update from offscreen
  169.  
  170. ; We don't have an offscreen buffer, so this is what we are going to do. First
  171. ; save the old port (the window that we are updating). Then, try to get an
  172. ; offscreen GrafPort for buffering. If that is successful, then the port will
  173. ; be set to it. Regardless of the outcome, however, we will draw the entire
  174. ; contents to whatever is active. Then we check the status of the
  175. ; GetOffScreenBuffer call. If it succeeded, then copy the buffer's contents
  176. ; to the window. If it didn't then what we drew appeared on the screen anyway,
  177. ; and we're done.
  178.  
  179.  
  180.                     lda oldPort         ; pass the window pointer in X & Y
  181.                     ldx oldPort+2
  182.                     jsr GetOffScreenBuffer ; changes the port if successful
  183.                     php                 ; save the status of this call
  184.                     jsl DrawByHand      ; draw the contents to cache or screen
  185.  
  186.                     PushLong oldPort    ; reset the port to window port
  187.                     _SetPort
  188.  
  189.                     plp                 ; Did offscreen caching occur?
  190.                     bcc SetUp           ; yes - now try again
  191.                     bcs done            ; no - we drew to screen - so exit.
  192.  
  193. haveBuffer          ANOP
  194. ;
  195. ; We have an offscreen buffer. Prepare the stack for a PPToPort call.
  196. ;
  197.                     ldy #6              ; push on source LocInfo pointer
  198.                     PushWord [CPPtr],y  ; This pointer points to the LocInfo
  199.                     dey                 ; of the OffScreen buffer, and is
  200.                     dey                 ; stored in the Cached Record.
  201.                     PushWord [CPPtr],y
  202.  
  203. ;
  204. ; We push on a pointer to VisRect here, but haven't yet initialized it! But
  205. ; don't worry. We will fill in VisRect down below.
  206. ;
  207.                     PushLong #VisRect   ; pass the pointer to the visrect.
  208.  
  209.                     lda oldPort         ; get the pointer to the dest port.
  210.                     sta Deref
  211.                     lda oldPort+2
  212.                     sta Deref+2
  213.  
  214. ; Now we need to tell PPToPort what part of the screen to update. This is
  215. ; done by looking at the VisRgn (which contains the intersection of the
  216. ; update region and the VisRgn). The format of a region is:
  217. ;
  218. ;  WORD: rgnSize  Size of the region
  219. ;  RECT: rgnBBox  rectangle the just surrounds the region
  220. ;  XXXX: rgnData  region data the would get me fired if I told you what it was.
  221. ;
  222. ; By using rgnBBox as our source/destination rectangle, we make PPToPort do
  223. ; as little work as possible; There won't be anything to update outside of
  224. ; that rectangle.
  225. ;
  226.                     ldy #ovisRgn+2      ; Find the visible rectangle.
  227.                     lda [Deref],y       ; First get the handle to the visRgn.
  228.                     sta temp2+2
  229.                     dey
  230.                     dey
  231.                     lda [Deref],y
  232.                     sta temp2
  233.  
  234.                     ldy #2              ; Deref the VisRgn handle
  235.                     lda [temp2],y
  236.                     sta temp1+2
  237.                     lda [temp2]
  238.                     sta temp1
  239.  
  240.                     ldy #8              ; finally copy the rect out of the
  241. loop                lda [temp1],y       ; VisRgn into a local variable.
  242.                     sta VisRect-2,y
  243.                     dey
  244.                     dey
  245.                     bne loop
  246.  
  247. ;
  248. ; VisRect now holds the rectangle that surrounds the entire area to udpate.
  249. ; This makes that "PushLong #VisRect" above point to valid data!
  250. ;
  251. ; Now we push on the destination for the PPToPort command. Since PPToPort
  252. ; doesn't do any scaling, all we need is the upper-left hand point of the
  253. ; destination; the lower left corner is calculated by QuickDraw by using the
  254. ; height and width of the source.
  255.  
  256.                     PushLong VisRect    ; use the upper left hand corner of the
  257. *                                       ; source rectangle as the destination.
  258.  
  259.                     PushWord #modeCopy  ; Set the transfer mode.
  260.                     _PPToPort           ; Blit those bits!!!
  261.  
  262.                     pha                 ; push on room for GetWRefcon result
  263.                     pha
  264.                     PushLong oldPort
  265.                     _GetWRefCon
  266.                     _HUnlock            ; unlock the Cache record handle
  267.  
  268. done                ANOP
  269.                     plb                 ; restore caller's data bank register
  270.                     pld                 ; restore caller's direct page reg.
  271.  
  272.                     rtl                 ; return to TaskMaster
  273.  
  274. oldPort             entry
  275.                     ds 4
  276. VisRect             ds 8
  277.  
  278.                     end
  279.  
  280.                     EJECT
  281. *******************************************************************************
  282. *
  283. SlowDraw            start
  284. *
  285. * Description:      This routine calls the routine that draws the test window
  286. *                   contents. It takes the place of the 'CacheContents'
  287. *                   routine for Windows 1 and 2. It does NOT cache the window
  288. *                   contents, and is used to show the difference between
  289. *                   cached and non-cached updating.
  290. *
  291. *
  292. * Inputs:
  293. *
  294. * Outputs:
  295. *
  296. * External Refs:
  297. *                   Import DrawContent
  298. *
  299. * Entry Points:
  300. *
  301. *******************************************************************************
  302.                     using Globals
  303.  
  304. ;
  305. ; SlowDraw is called from the Window Manager to update the contents
  306. ; of the window. Therefore, the Direct Page and Data Bank Register may
  307. ; not be set to what our application had them set to. Save the settings
  308. ; as the Window Manager had them, and then set them up the way we like
  309. ; them. That way we can use local (2-byte absolute) addressing, and can
  310. ; access our Direct Page variables.
  311. ;
  312.                     phd
  313.                     phb
  314.  
  315.                     phk
  316.                     plb
  317.                     lda MyDP
  318.                     tcd
  319.  
  320.                     pha
  321.                     pha
  322.                     _GetPort
  323.                     pla
  324.                     plx
  325.  
  326.                     jsl DrawContent
  327.  
  328.                     plb
  329.                     pld
  330.  
  331.                     rtl
  332.                     end
  333.  
  334.                     EJECT
  335. *******************************************************************************
  336. *
  337. DrawByHand          start
  338. *
  339. * Description:      The contents need to be created for the first time. The
  340. *                   address of theroutine that doesthis is in a parameter
  341. *                   block pointed to by the RefCon. Get this address, push it
  342. *                   on the stack, and load up A and X with the pointer to the
  343. *                   window so that the drawing routine can have information
  344. *                   about it (the actual port it is drawing to is an offscreen
  345. *                   port, and does not have window information in it, like the
  346. *                   window title).
  347. *
  348. *
  349. * Inputs:           NONE
  350. *
  351. * Outputs:          NONE
  352. *
  353. * External Refs:
  354. *                   Import oldPort
  355. *
  356. * Entry Points:     NONE
  357. *
  358. *******************************************************************************
  359.                     using Globals
  360.  
  361.                     ldy #1              ; Get bytes 1 and 2 of drawing routine.
  362.                     PushWord [CPPtr],y  ; push bytes 1 and 2 on.
  363.                     phb                 ; push one byte onto the stack.
  364.                     lda [CPPtr]         ; Get bytes 0 and 1 into Acc.
  365.                     sta 1,s             ; now store bytes 0 and 1 on the stack
  366.                     lda oldPort         ; set up A & X for the drawing routine
  367.                     ldx oldPort+2
  368.                     rtl                 ; RTL to the drawing routine
  369.  
  370.                     end
  371.  
  372.                     EJECT
  373. *******************************************************************************
  374. *
  375. DrawOdyRtn          start
  376. *
  377. * Description:      This routine posts the first few pages of Sculley's book
  378. *                   into the Cache buffer or onto the screen. It uses TextBox2
  379. *                   and takes a while, so tell the user by showing a watch.
  380. *
  381. *                   None of what I do here requires the use of my Direct Page
  382. *                   or 2-byte absolute addressing, so I don't need to change
  383. *                   the Direct Page or Data Bank Registers. However, other
  384. *                   routines that perform updating will normally need to change
  385. *                   these. The CacheContents routine demonstrates the
  386. *                   technique.
  387. *
  388. *
  389. * Inputs:           A = low order word of window pointer
  390. *                   X = high order word
  391. *
  392. * Outputs:          NONE
  393. *
  394. * External Refs:    NONE
  395. *
  396. * Entry Points:     NONE
  397. *
  398. *******************************************************************************
  399.                     using Globals
  400.  
  401. ;
  402. ; --- We'll be sitting here for a while, so tell the user.
  403. ;
  404.                     _WaitCursor
  405.  
  406.                     jsl xorPoint
  407.                     PushLong #Odyssey   ; push pointer to text
  408.                     PushWord #OdysseyEnd-Odyssey            ; length of text
  409.                     PushLong #OdyRect   ; bounds to fit the text into
  410.                     PushWord #0         ; Fill justify
  411.                     _LETextBox2         ; draw it all!
  412.  
  413.                     _InitCursor         ; set cursor back to arrow.
  414.  
  415. * This routine is necessary to work around a bug in system disk 5.0.  The fastFont
  416. * routine has a problem with pixelmaps that are larger than 64k.  The fastFont
  417. * routine is used only when the regions are rectangular and no region clipping
  418. * is involved.  If either the clipRgn or visRgn is not rectangular, then fastFont
  419. * is not used.  This method of "turning it off" is what we will use to work around
  420. * the bug.  Note that the visRgn is made non-rectangular.  This would normally
  421. * be a bad thing.  However, setting the clipRgn non-rectangular does not work in
  422. * this case because LETextBox2 sets the clipRgn to a rectangular region the size
  423. * of the rectangle for the text.  So, setting the clipRgn to be non-rectangular
  424. * is defeated by the LETextBox2 routine.  This is why the visRgn is used.
  425. * Also note that for off-screen grafPorts, the visRgn IS your property, so it
  426. * is okay to modify it.  Also note that the modification to the visRgn is undone
  427. * after the LETextBox2 call.
  428.  
  429. xorPoint            pha
  430.                     pha
  431.                     _NewRgn             ; Temp region handle now on stack.
  432.  
  433.                     lda 3,s             ; Duplicate region handle on stack.
  434.                     pha
  435.                     lda 3,s
  436.                     pha
  437.  
  438.                     ldy #-1             ; Push rect of -1,-1,0,0
  439.                     phy
  440.                     phy
  441.                     iny
  442.                     phy
  443.                     phy
  444.                     _SetRectRgn         ; Temp region handle still on stack.
  445.  
  446.                     lda 3,s             ; Duplicate region handle on stack.
  447.                     pha
  448.                     lda 3,s
  449.                     pha
  450.  
  451.                     pha
  452.                     pha
  453.                     _GetVisHandle       ; visRgn handle on stack.
  454.  
  455.                     lda 3,s             ; Duplicate visRgn handle on stack.
  456.                     pha
  457.                     lda 3,s
  458.                     pha
  459.  
  460.                     _XorRgn             ; Xor point in visRgn.
  461.                     _DisposeRgn         ; Dispose of visRgn.
  462.  
  463.                     rtl                 ; Back to caller.
  464.  
  465. OdyRect             dc i2'0,10,790,590'
  466.  
  467.                     end
  468.  
  469.                     EJECT
  470. *******************************************************************************
  471. *
  472. DrawContent         start
  473. *
  474. * Description:      This is the real procedure that draws the contents of the
  475. *                   Test windows. It merely draws the name of the window many
  476. *                   times.
  477. *
  478. *
  479. * Inputs:           A = low order word of window pointer
  480. *                   X = high order word
  481. *
  482. * Outputs:          NONE
  483. *
  484. * External Refs:    NONE
  485. *
  486. * Entry Points:     NONE
  487. *
  488. *******************************************************************************
  489.                     using Globals
  490.  
  491.                     sta myPort          ; save window pointer
  492.                     stx myPort+2
  493.  
  494.                     pha                 ; room for window title pointer
  495.                     pha
  496.                     phx                 ; push on window pointer
  497.                     pha
  498.                     _GetWTitle          ; get the window's title
  499.                     PullLong wTitle
  500.  
  501.                     lda #10             ; now initialize the X and Y variables
  502.                     sta yLoc            ; that we use to draw the strings.
  503.                     lda #0
  504.                     sta xLoc
  505.                     lda #10             ; loop 10 times down the screen
  506.                     sta bigCounter
  507. loop                ANOP
  508.                     PushWord xLoc       ; set up for the Moveto
  509.                     PushWord yLoc
  510.                     _MoveTo
  511.  
  512.                     lda #8              ; loop 8 times across the screen
  513.                     sta littleCounter
  514. loop2               ANOP
  515.                     PushLong wTitle     ; put window title pointer onto stack
  516.                     _DrawString         ; and draw the string
  517.                     dec littleCounter   ; update our horizontal counter
  518.                     bpl loop2
  519.  
  520.                     lda yLoc            ; update the X/Y coordinates
  521.                     clc
  522.                     adc #10
  523.                     sta yLoc
  524.                     lda xLoc
  525.                     sec
  526.                     sbc #20
  527.                     sta xLoc
  528.                     dec bigCounter      ; update our vertical counter
  529.                     bpl loop            ; ...and check it.
  530.  
  531.                     rtl
  532.  
  533. xLoc                ds 2                ; where to start drawing string next
  534. yLoc                ds 2                ; where to start drawing string next
  535. littleCounter       ds 2                ; counter across the screen
  536. bigCounter          ds 2                ; counter down the screen
  537.  
  538. myPort              ds 4
  539. wTitle              ds 4
  540.  
  541.                     end
  542.  
  543.                     EJECT
  544. *******************************************************************************
  545. *
  546. GetOffScreenBuffer  start
  547. *
  548. * Description:      Get a handle to an offscreen GrafPort. If _NewHandle call
  549. *                   fails, set the carry and return. If it succeeds, create a
  550. *                   new bitmap for it, install the bitmap, and initialize the
  551. *                   appropriate fields. Finally, install the pointer to the
  552. *                   GrafPort in the cache record for the window, clear the
  553. *                   carry, and return with the port set to the new port.
  554. *
  555. *                   This routine is entered with the pointer to the window
  556. *                   manager port of the window we are updating. In case we
  557. *                   cannot get an offscreen buffer, we can reset the port to
  558. *                   this.
  559. *
  560. *
  561. * Inputs:           A = low word of window pointer of window we are updating
  562. *                   X = high word
  563. *
  564. * Outputs:          NONE
  565. *
  566. * External Refs:    NONE
  567. *
  568. * Entry Points:     NONE
  569. *
  570. *******************************************************************************
  571.                     using Globals
  572.  
  573.                     sta origPort        ; save the window manager port
  574.                     stx origPort+2
  575.  
  576. ;
  577. ; --- Get a memory for a new grafport
  578. ;
  579.                     stz newPort         ; assume that we don't get it.
  580.                     stz newPort+2
  581.                     pha                 ; space for the new handle
  582.                     pha
  583.                     PushLong #portSize
  584.                     PushWord MyID
  585.                     PushWord #attrFixed ; plus 'attrNoCross' if on old ROMs
  586.                     PushLong #$0000
  587.                     _NewHandle
  588.                     PullLong Deref
  589.                     bcs error
  590.  
  591.                     ldy #2              ; Dereference and lose the handle
  592.                     lda [Deref],y       ; (we only need a pointer)
  593.                     tax
  594.                     lda [Deref]
  595.                     sta newPort
  596.                     stx newPort+2
  597.  
  598.                     phx                 ; Now initialize it as a GrafPort
  599.                     pha
  600.                     _OpenPort
  601.                     bcs error
  602. ;
  603. ; --- We now have a port to play with, but its PixImage is the
  604. ; --- screen. Let's change that.
  605. ;
  606.                     jsr AddPixMap
  607.                     bcs error
  608.  
  609. ; Everything is all set up. The current port should still be the one
  610. ; we just created with the _OpenPort above. All we have to do is install
  611. ; the pointer to it into the cacheParms block for the Window.
  612.  
  613.                     ldy #4
  614.                     lda newPort
  615.                     sta [CPPtr],y
  616.                     iny
  617.                     iny
  618.                     lda newPort+2
  619.                     sta [CPPtr],y
  620.  
  621.                     clc
  622.                     rts
  623. error               ANOP
  624.                     pha                 ; Error occured. Get the handle to the
  625.                     pha                 ; port that we created; dispose of it.
  626.                     PushLong newPort
  627.                     _FindHandle
  628.                     bcs skip
  629.                     _DisposeHandle
  630. skip                ANOP
  631.                     PushLong origPort
  632.                     _SetPort
  633.                     sec
  634.                     rts
  635.  
  636. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  637. ;
  638. ; This routine adds an offscreen PixMap to the Grafport pointed to by
  639. ; 'newPort'.
  640. ;
  641. AddPixMap           ANOP
  642.                     jsr CalcScrnDims    ; get values for LocInfo
  643.  
  644.                     pha                 ; get a PixImagePtr of right size
  645.                     pha
  646.                     PushLong scrnSize
  647.                     PushWord MyID
  648.                     PushWord #attrFixed ; plus 'attrNoCross' if on old ROMs
  649.                     PushLong #$0000
  650.                     _NewHandle
  651.                     PullLong Deref
  652.                     bcs error2
  653.  
  654. ;
  655. ; Get the Window Pointer into a Direct Page location (temp1) for
  656. ; easy access later.
  657. ;
  658.                     lda newPort
  659.                     sta temp1
  660.                     lda newPort+2
  661.                     sta temp1+2
  662.  
  663.                     ldy #2              ; Dereference and lose the handle
  664.                     lda [Deref],y       ; to the PixImage (it's locked)
  665.                     tax
  666.                     lda [Deref]         ; (pointer in A and X)
  667.  
  668.                     ldy #optrToPixImage ; install the new PixImage
  669.                     sta [temp1],y
  670.                     iny
  671.                     iny
  672.                     txa
  673.                     sta [temp1],y
  674.  
  675.                     ldy #owidth         ; set the 'rowBytes' value
  676.                     lda rowBytes
  677.                     sta [temp1],y
  678.  
  679.                     ldy #oboundsRect+4  ; update the size of the boundsRect
  680.                     lda scrnHeight
  681.                     sta [temp1],y
  682.                     iny
  683.                     iny
  684.                     lda scrnWidth
  685.                     sta [temp1],y
  686.  
  687.                     ldy #oportRect+4    ; and the size of the portrect
  688.                     lda scrnHeight
  689.                     sta [temp1],y
  690.                     iny
  691.                     iny
  692.                     lda scrnWidth
  693.                     sta [temp1],y
  694.  
  695. ;
  696. ; Set the VisRgn and ClipRgn to the size of the port we just
  697. ; created. This is done by calling ClipRect with the portRect,
  698. ; and then copying the resulting ClipRgn to the VisRgn.
  699. ;
  700.                     lda temp1           ; Create a pointer to the portRect
  701.                     clc                 ; in the Window Record (remember,
  702.                     adc #oportRect      ; temp1 points to the WindRec).
  703.                     tax
  704.                     lda temp1+2
  705.                     adc #0
  706.                     pha                 ; push on one set for _EraseRect
  707.                     phx
  708.                     pha                 ; push on this set for _ClipRect
  709.                     phx
  710.                     _ClipRect
  711.  
  712.                     ldy #oclipRgn+2     ; now copy the ClipRgn to the VisRgn
  713.                     PushWord [temp1],y
  714.                     dey
  715.                     dey
  716.                     PushWord [temp1],y
  717.                     _SetVisRgn
  718.  
  719.                     _EraseRect          ; rect ptr left on from way before.
  720.  
  721.                     clc
  722.                     rts
  723.  
  724. error2              ANOP
  725.                     sec
  726.                     rts
  727.  
  728. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  729. ;
  730. ; Calculate the screen size based on the general formula:
  731. ;
  732. ;    rowBytes := (((((right - left) * theDepth) + 7) DIV 8) + 7) AND ~%111
  733. ;
  734. ; in English, or what passes for it when I type, this says: take the width
  735. ; of the GrafPort, and multiply it by the depth (number of bits per pixel)
  736. ; of the screen. Add 7 to this and divide by 8 to get the number of bytes
  737. ; that this takes up (add 7 effectively rounds up, to counter the DIV 8's
  738. ; rounding down). After we have the number of bytes, we have to make sure that
  739. ; this is an "even multiple of 8", as it states in the QuickDraw Chapter. This
  740. ; is done by adding 7 (again, to round up) and stripping off the low 3 bits,
  741. ; which performs the rounding down to the nearest multiple of 8.
  742. ;
  743. ; This formula can be slightly reduced to:
  744. ;
  745. ;    rowBytes := ((((right - left) * theDepth) + 63) DIV 8) AND ~%111
  746. ;
  747. ; which is used in specific:
  748. ;
  749. ;    rowBytes := (((scrnWidth * 2) + 63) DIV 8) AND ~%111
  750. ;
  751. CalcScrnDims        ANOP
  752.                     ldy #10             ; get the screen width from cacheParms
  753.                     lda [CPPtr],y
  754.                     sta scrnWidth
  755.                     asl a               ; times 2
  756. ;                   asl a               ; use this also if in 320 mode
  757.                     clc                 ; add 63
  758.                     adc #63
  759.                     lsr a               ; divide by 8
  760.                     lsr a
  761.                     lsr a
  762.                     and #%11111000      ; and with ~%111
  763.                     sta rowBytes
  764.                     pha                 ; Now prepare to multiply to get
  765.                     pha                 ; the whole screen size.
  766.                     pha                 ; Multiplier
  767.                     dey
  768.                     dey
  769.                     lda [CPPtr],y
  770.                     sta scrnHeight
  771.                     pha                 ; Multiplicand
  772.                     _Multiply
  773.                     PullLong scrnSize
  774.                     rts
  775.  
  776. origPort            ds 4
  777. newPort             ds 4
  778.  
  779. scrnSize            ds 4
  780. scrnHeight          ds 2
  781. scrnWidth           ds 2
  782. rowBytes            ds 2
  783.  
  784.                     end
  785.  
  786.                     copy Jiffy.stds.asm
  787.  
  788.                     END
  789.